home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-23 | 7.4 KB | 347 lines | [TEXT/ttxt] |
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /*
- #define DEBUG 1
- */
- #define BOD "Info-Mac Digest "
- #define EOD "End of Info-Mac Digest"
- #define BOT "Today's Topics:"
- #define EOT "--------------------------------------------------------------------"
- #define EOM "------------------------------\n"
- #define BOF "[Archived as "
- #define FTP "\nFetch from <a href=ftp://sumex-aim.stanford.edu%s>SUMEX</a>"
- #define FUN ", \n<a href=ftp://src.doc.ic.ac.uk/computing/systems/mac%s>UK</a>"
- #define USA ", \n<a href=ftp://ftp.hawaii.edu/mirrors%s>Hawaii</a>"
- #define JAP ", \n<a href=ftp://ftp.u-tokyo.ac.jp/pub%s>U-Tokyo</a>"
- #define CAN ", \n<a href=ftp://ftp.ucs.ubc.ca/pub/mac%s>Canada</a>"
- #define NED ", \n<a href=ftp://ftp.fenk.wau.nl/pub/mac%s>The Netherlands</a>"
- #define SWD ", \n<a href=ftp://ftp.sunet.se/mac%s>Sweden</a>"
- #define MOR 10 /* maximum items overrun */
- #define DRE "http://dutera.et.tudelft.nl/people/vdham/vdham.html"
-
- FILE *outP, *inP;
-
- #ifdef THINKC
- #define REMOVE_ALL_EVENTS 0
- #define MY_PROMPT "\pChoose INFOMAC e-mail file:"
- #define NIL_FILE_FILTER NULL
- #define NIL_DIALOG_HOOK NULL
-
- /****************************** GetFileName *******/
- GetFileName( replyPtr )
- SFReply *replyPtr;
- {
- Point myPoint;
- SFTypeList typeList;
- int numTypes;
-
- myPoint.h = 100;
- myPoint.v = 100;
- typeList[ 0 ] = 'TEXT';
- numTypes = 1;
-
- SFGetFile( myPoint, MY_PROMPT, NIL_FILE_FILTER, numTypes,
- &typeList, NIL_DIALOG_HOOK, replyPtr );
- }
-
- #endif
-
- int ParseOne(int buttonsOn)
- {
- char line[512], tempLine[512];
- int num, i, l;
- int tocItem = 0;
- int msgItem = 0;
- int found;
- char name[256];
- char *cptr;
-
- /* find issue */
-
- printf("Parsing...\n");
-
- found = 0;
-
- do {
- if( fgets( line, 256, inP ) != NULL )
- {
- if( strstr( line, BOD ) != NULL )
- {
- printf("Found %s\n", BOD);
- printf(line);
- found = 1;
- cptr = (char *)strstr( line, "Issue" );
- if( cptr==NULL )
- {
- printf("Can't find issue number\n");
- return(0);
- }
- num = atoi( cptr+6 );
- sprintf(name, "issue%d.html", num);
- printf("name = '%s'\n", name);
- if( (outP = fopen( name,"w")) == NULL )
- {
- printf("Can't open '%s'\n", name );
- return(0);
- }
- }
- }
- else
- return(0);
- } while( !found );
-
- #ifdef DEBUG
- printf("Title found\n");
- #endif
-
- fprintf(outP,"<TITLE>Issue %d</TITLE>\n", num);
- fprintf(outP,"<pre>\n");
- fprintf(outP,"%s\n",line);
-
- /* find toc */
-
- found = 0;
-
- do {
- if( fgets( line, 256, inP ) != NULL )
- {
- if( strstr( line, BOT ) != NULL )
- {
- found = 1;
- }
- }
- else
- {
- fclose( outP );
- return(0);
- }
- } while( !found );
-
-
- #ifdef DEBUG
- printf("TOC found\n");
- #endif
-
- line[strlen(line)-1] = 0;
- fprintf(outP, "<a name=toc>%s</a>\n", line);
-
- fgets( line, 256, inP ); /* get empty line */
- fputs("<ul>\n", outP);
-
- while( strlen(fgets( line, 256, inP ))>1 )
- {
- i=0;
- while( i<strlen(line) && line[i]==' ' ) i++;
- if( i==strlen(line) ) i=0;
-
- tocItem++;
- line[strlen(line)-1]=0; /* terminate line with 0 */
- fprintf(outP, "<li><a name=toc%d> </a><a href=#item%d>%s</a>\n",
- tocItem, tocItem, line+i);
- }
-
- fprintf(outP, "</ul>\n\n\n");
-
- while( strstr( fgets(line, 256, inP), EOT ) == NULL )
- fputs( line, outP );
-
- fputs( line, outP );
-
- found = 0;
-
- do{
- msgItem++;
-
- fprintf( outP, "<a name=item%d> </a>",msgItem);
-
- if( buttonsOn )
- {
- fprintf( outP, "<a href=#item%d><img src=next.gif alt=Next></a> ", msgItem+1);
- if( msgItem>tocItem )
- fprintf( outP, "<a href=#toc><img src=toc.gif alt=TOC></a>\n");
- else
- fprintf( outP, "<a href=#toc%d><img src=toc.gif alt=TOC></a>\n", msgItem);
- }
- else
- {
- fprintf( outP, "<a href=#item%d>Next</a> ", msgItem+1);
- if( msgItem>tocItem )
- fprintf( outP, "<a href=#toc>TOC</a>\n");
- else
- fprintf( outP, "<a href=#toc%d>TOC</a>\n", msgItem);
- }
-
- while( strcmp( fgets( line, 256, inP ), EOM )!=0 &&
- strstr( line, EOD ) == NULL && !feof(inP) )
- {
- /* filter entities in mail */
-
- tempLine[0]=0;
- l = 0;
- for(i=0; i<strlen(line); i++ )
- {
- if( line[i]=='<' )
- {
- tempLine[l++] = '&';
- tempLine[l++] = 'l';
- tempLine[l++] = 't';
- tempLine[l++] = ' ';
- }
- else
- if( line[i]=='>' )
- {
- tempLine[l++] = '&';
- tempLine[l++] = 'g';
- tempLine[l++] = 't';
- tempLine[l++] = ' ';
- }
- else
- if( line[i]=='"' )
- {
- tempLine[l++] = '&';
- tempLine[l++] = 'q';
- tempLine[l++] = 'u';
- tempLine[l++] = 'o';
- tempLine[l++] = 't';
- tempLine[l++] = ' ';
- }
- else
- if( line[i]=='&' )
- {
- tempLine[l++] = '&';
- tempLine[l++] = 'a';
- tempLine[l++] = 'm';
- tempLine[l++] = 'p';
- tempLine[l++] = ' ';
- }
- else
- {
- tempLine[l++] = line[i];
- tempLine[l] = 0;
- }
- }
- strcpy( line, tempLine );
-
- fputs(line, outP);
-
- if( (cptr=strstr( line, "/info-mac/" )) != NULL )
- {
- num = cptr-line;
- i = 0;
- while( line[num] != ';' && num<strlen(line) && i<256 )
- {
- name[i]=line[num];
- i++;
- num++;
- }
- name[i] = 0;
- line[strlen(line)-1]=0;
- fprintf( outP, "\n</pre>" );
-
- fprintf( outP, FTP, name);
- fprintf( outP, FUN, name);
- fprintf( outP, USA, name);
- fprintf( outP, JAP, name);
- fprintf( outP, CAN, name);
- fprintf( outP, NED, name);
- fprintf( outP, SWD, name);
-
- fprintf( outP, ".\n<pre>\n" );
- }
- }
- fputs( line, outP );
-
- }while( strstr( line, EOD ) == NULL && msgItem<(tocItem+MOR) && !feof( inP ) );
-
- fprintf( outP, "</pre>\n" );
- fputs("<p><hr><p>\n", outP);
- fprintf( outP, "<a name=item%d> </a>",msgItem+1);
- fputs("HTML file created by digester<p>\n", outP);
- fprintf(outP,"Digester developed by: <a href=%s>André C. van der Ham</a><p>\n", DRE);
- fputs("<address>\n", outP);
- fputs("Send bug reports, questions, etc. to: A.C.vanderHam@ET.TUDelft.NL<p>\n", outP);
- fputs("</address>\n", outP);
-
- fclose( outP );
-
- printf("file closed.\n");
-
- if( feof( inP ) )
- printf("Premature end of file found on input file.\n");
-
- if( msgItem != tocItem )
- printf("!! msgItem = %d, tocItem = %d\n", msgItem, tocItem );
-
- return(1);
- }
-
- int main( void )
- {
- char name[80];
- char line[256];
- int i;
-
- #ifdef THINKC
- SFReply reply;
- #endif
-
- int okay=1;
-
- puts("\n\n*** D I G E S T E R ***\n");
- puts("by Andre' C. van der Ham\n");
- puts("This program parses info-mac digests you get by e-mail.");
- puts("Save the e-mail without headers and paragraph recognition (Eudora)");
-
- #ifndef THINKC
- puts("Convert file to appropriate ascii format, for example: Mac->Unix\n");
- #endif
-
- puts("The file can contain a number of digests.");
- puts("An HTML file is generated for each issue.");
- puts("Send bug reports, questions, etc... to:");
- puts("e-mail: A.C.vanderHam@ET.TUDelft.NL\n\n");
-
- #ifndef THINKC
- printf("Input file: ");
- gets( name );
- #endif
-
- #ifdef THINKC
- puts("WARNING: this program only works if the DIGESTER program and the e-mail file");
- puts("are in the same folder (sorry).");
- puts("");
- puts("Click mouse to continue.");
- while(!Button());
- FlushEvents( everyEvent, REMOVE_ALL_EVENTS );
-
- GetFileName( &reply );
-
- if( reply.good!=TRUE )
- {
- return(1);
- }
-
- for(i=0;i<reply.fName[0]; i++ )
- name[i]=reply.fName[i+1];
-
- name[i]=0;
- #endif
-
- if( (inP = fopen( name, "r" )) != NULL )
- {
- while( okay )
- {
- okay = ParseOne(1);
-
- #ifdef DEBUG
- printf("%d: next...\n", okay);
- #endif
-
- }
-
- fclose( inP );
- }
-
- return(0);
- }